package org.kjk.mail;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class GMailSubjectController extends AbstractController {
	private GMail gmail;
	public List<GMailDTO> mail = null;

	@SuppressWarnings("unchecked")
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("Page Loading");
		mail = (List<GMailDTO>) request.getSession().getAttribute("mail");
		String refresh = request.getParameter("refresh");
		if (mail == null || (refresh != null && refresh.equals("true"))) {
			System.out.println("refresh mail list");
			mail = gmail.getSubject();
		}
		if (mail == null) {
			return new ModelAndView("/mail/gmailLogin.jsp");
		}
		request.getSession().setAttribute("mail", mail);
		System.out.println("page load success");
		return new ModelAndView("/mail/mail.jsp", "mail", mail);
	}

	public void setGmail(GMail gmail) {
		this.gmail = gmail;
	}

}
